This repository has been archived by the owner on Nov 1, 2023. It is now read-only.
Only use pseudo-handle for coverage dbghelp
context
#918
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #914.
Summary
When recording coverage, don't try to use live process handles as the context for the
dbghelp
symbol handler in the module feature cache. Instead, use the default pseudo-handle for the semantically static PDB search, and the target process handle for any queries about the target and its address space.Details
The docs for
SymInitializeW
fromdbghelp
are a bit unclear on the exact constraints (and failure modes) around theHANDLE
one uses to interact with the symbol handler in alldbghelp
functions.The docs for the
HANDLE hProcess
parameter say:Because the coverage recorder is debugging the target process, we follow this guidance. We (schedule!) initialization of the symbol handler on
CREATE_PROCESS_DEBUG_EVENT
, and try to use the process's handle as the symbol handler context when searching for the PDB.However, this doesn't really seem to be necessary, adds some complications, and doesn't work when we do our PDB search:
maybe_sym_initialize()
avoids double-dbghelp
init, but only forces ourdbghelp
wrapper to internally schedule initialization (pending observation of the process's initial breakpoint). But in coverage recording, we try to use the handle as a symbol handler context immediately, before actual symbol handler init, when searching for a PDB associated with the process's executable module. This then fails, and we cannot extract coverage features for the new process.CREATE_PROCESS_DEBUG_EVENT
), which would guarantee we aren't using the "wrong" (pseudo-)handle.It appears we can sidestep this issue by exclusively using the custom, (non-
GetCurrentProcess()
) pseudo-handle incoverage::pdb
when usingdbghelp
for PDB search. As required by the docs, this uniquely "identifies the caller", perhaps at the cost of redundant handler init.In the future, we should revisit our
dbghelp
wrapper to have a more explicit notion of context that hides the inheritedHANDLE
, and presents a misuse-resistant API (captured in #917).